package com.ruoyi.shop.emporium.issue.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.common.domain.DtsIssue;
import com.ruoyi.shop.emporium.issue.service.IDtsIssueService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 通用问题Controller
 *
 * @author ruoyi
 * @date 2025-02-13
 */
@RestController
@RequestMapping("/emporium/issue")
public class DtsIssueController extends BaseController
{
    @Autowired
    private IDtsIssueService dtsIssueService;

    /**
     * 查询通用问题列表
     */
    @PreAuthorize("@ss.hasPermi('emporium:issue:list')")
    @GetMapping("/list")
    public TableDataInfo list(DtsIssue dtsIssue)
    {
        startPage();
        List<DtsIssue> list = dtsIssueService.selectDtsIssueList(dtsIssue);
        return getDataTable(list);
    }

    /**
     * 导出通用问题列表
     */
    @PreAuthorize("@ss.hasPermi('emporium:issue:export')")
    @Log(title = "通用问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DtsIssue dtsIssue)
    {
        List<DtsIssue> list = dtsIssueService.selectDtsIssueList(dtsIssue);
        ExcelUtil<DtsIssue> util = new ExcelUtil<DtsIssue>(DtsIssue.class);
        util.exportExcel(response, list, "通用问题数据");
    }

    /**
     * 获取通用问题详细信息
     */
    @PreAuthorize("@ss.hasPermi('emporium:issue:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dtsIssueService.selectDtsIssueById(id));
    }

    /**
     * 新增通用问题
     */
    @PreAuthorize("@ss.hasPermi('emporium:issue:add')")
    @Log(title = "通用问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DtsIssue dtsIssue)
    {
        return toAjax(dtsIssueService.insertDtsIssue(dtsIssue));
    }

    /**
     * 修改通用问题
     */
    @PreAuthorize("@ss.hasPermi('emporium:issue:edit')")
    @Log(title = "通用问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DtsIssue dtsIssue)
    {
        return toAjax(dtsIssueService.updateDtsIssue(dtsIssue));
    }

    /**
     * 删除通用问题
     */
    @PreAuthorize("@ss.hasPermi('emporium:issue:remove')")
    @Log(title = "通用问题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dtsIssueService.deleteDtsIssueByIds(ids));
    }
}
